﻿using FluentValidation;
using Mes.Application.DTO.Inputs.MasterData;

namespace Mes.Application.Web.Validators.MaterialClassValidators
{
    public class AddMaterialInputValidator : AbstractValidator<AddMaterialInput>
    {
        public AddMaterialInputValidator()
        {
            RuleFor(x => x.Name).NotEmpty().WithMessage("物料名称不能为空")
                                .Length(1,50).WithMessage("物料名称长度必须在1到50之间");
            RuleFor(x => x.Code).NotEmpty().WithMessage("物料编码不能为空")
                               .Length(1, 50).WithMessage("物料编码长度必须在1到50之间");
            RuleFor(x => x.MaterialClassId).GreaterThan(0).WithMessage("物料类Id必须大于0");
            RuleFor(x => x.MaterialClassName).NotEmpty().WithMessage("物料类名称不能为空")
                               .Length(1, 50).WithMessage("物料类名称长度必须在1到50之间");
            RuleFor(x => x.MeasuringUnitId).GreaterThan(0).WithMessage("计量单位Id必须大于0");
            RuleFor(x => x.MeasuringUnitName).NotEmpty().WithMessage("计量单位名称不能为空")
                               .Length(1, 50).WithMessage("计量单位名称长度必须在1到50之间");
            RuleFor(x => x.PrecisionPlace).GreaterThanOrEqualTo(0).WithMessage("小数位数必须大于等于0").LessThanOrEqualTo(7).WithMessage("小数位数必须小于等于7");          
            RuleFor(x => x.Remark).Length(0, 200).WithMessage("备注长度必须在0到200之间");
        }
    }
}
